<template>
  <div id="class" class="tags">
    <el-tag
      v-for="(tag, index) in tags"
      :key="tag.name"
      :closable="tag.name !== 'home'"
      :effect="$route.name == tag.name ? 'dark' : 'plain'"
      size="small"
      @click="changeMenu(tag)"
      @close="handle(tag,index)"
    >{{tag.lable}}</el-tag>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState({
      tags: (state) => state.tab.tabList,
    }),
  },
  methods: {
    changeMenu(item) {
        this.$router.push({
            name:item.name
        })
    },
    handle(tag,index){
         this.$store.commit('closeTag',tag)
         const length = this.tags.length -1;
         if(tag.name!=this.$route.name){
            return
         }
         if(index === length){
            this.$router.push({
                name:this.tags[index-1].name
            })
         }else{
             this.$router.push({
                name:this.tags[index].name
            })
         };
        
    }
  },
};
</script>
<style lang="less" scoped>
   .tags{
    padding: 20px;
    .el-tag{
        margin-right:15px ;
        cursor: pointer;
    }
   }
</style>